<?php

namespace XWAM\Controller;

/**
 * Advertising 控制器类
 *
 * @since 1.0 <2015-10-23> SoChishun <14507247@qq.com> Added.
 */
class Advert extends AppbaseController {

    function indexSearch() {
        $search = I('param.');        
        if (!empty($search['word'])) {
            $word = $search['word'];
            $where['_string'] = "`name` like '%$word%' or title like '%$word%' or code like '%$word%'";
        }
        // $where['site_id'] = $this->site_id;
        return array('search' => $search, 'where' => $where);
    }

    public function index() {
        $asearch = $this->indexSearch();
        $mAdvert = new \XWAM\Model\AdvertModel();
        $list = $mAdvert->where($where)->select();
        $this->assign('search', $asearch['search']);
        $this->assign('list', $list);
        $this->display();
    }

    function copy($id = 0) {
        if (!$id) {
            $this->ajaxMsg(false, '参数无效');
        }
        $mAdvert = new \XWAM\Model\AdvertModel();
        $mAdvert->copyAdvert($id);
        $this->ajaxMsg(true);
    }

    function edit($id = 0) {
        $data = array();
        if ($id) {
            $mAdvert = new \XWAM\Model\AdvertModel();
            $data = $mAdvert->find($id);
        }
        $this->assign('data', $data);
        $this->display();
    }

    function editSave() {
        $mAdvert = new \XWAM\Model\AdvertModel();
        $result = $mAdvert->saveAdvert();
        $this->dialogJump($result['status'], $result['info']);
    }

    function delete($id = '') {
        $mAdvert = new \XWAM\Model\AdvertModel();
        $result = $mAdvert->deleteAdvert($id);
        $this->ajaxReturn($result);
    }

}
